<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<script src="<ls:templateResource item='/resources/plugins/fullcalendar/lib/moment.min.js'/>" type="text/javascript"></script>
<link href="<ls:templateResource item='/resources/plugins/fullcalendar/fullcalendar.min.css'/>" rel="stylesheet"/>
<script src="<ls:templateResource item='/resources/plugins/fullcalendar/fullcalendar.min.js'/>" type="text/javascript"></script>
<script src="<ls:templateResource item='/resources/plugins/fullcalendar/locale/zh-cn.js'/>" type="text/javascript"></script>

<!-- HTML 代码 -->
<div id='calendar'></div>
        <script language="JavaScript" type="text/javascript">
        
			  $(document).ready(function() {
			        //国际化默认值为'en'，代表使用英文
			        var initialLocaleCode = 'zh-cn'; //中文

			     	 $('#calendar').fullCalendar({
			     	     defaultDate: '${date}',
				     	     header : {
	                             left : 'prevYear, prev,next, nextYear',
	                             center : 'title',
	                             right : 'today'
	                         },
			     	     editable: true,
			     	     eventLimit: true, // allow "more" link when too many events
			     	     weekends: true,
			     	     weekNumbers: true,
			     	     locale: initialLocaleCode,
			     	     navLinks: true, // can click day/week names to navigate views
				     	 events:function(start, end, timezone, callback){
				     		    //prev上一月, next下一月等事件时调用
				     		    //console.log(start)
				     		   // console.log(end)
				     		    //console.log(callback)
				     		    var userName = $("#userName").val();
							     $.ajax({
							    		url:"${contextPath}/admin/dailylog/queryTaskEstimate", 
							    		type:'post', 
							    		data:{"startDate":start.format(), "endDate":end.format(), "userName":userName},
							    		async : false, //默认为true 异步   
							    		success:function(result){
							    	        var events = [];
							    	        $.each(result,function(i,c) {
							    	          events.push({
                                                id: $(this).attr('id'),
							    	            title: $(this).attr('title'),
							    	            start: $(this).attr('start'), // will be parsed
							    	            end: $(this).attr('end')
							    	          });
							    	        });
							    	   
							    	       callback(events);
							    		}
							    	});
				     		 },
			     	     eventClick: function(calEvent, jsEvent, view) {
			     	    	taskEstimate(calEvent.start.format());//在事件上点击
/* 			     	        alert('Event: ' + calEvent.title + ", Start: " + calEvent.start);
			     	        alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
			     	        alert('View: ' + view.name);
			     	 
			     	        // change the border color just for fun
			     	        $(this).css('border-color', 'red'); */
			     	        return false;
			     	    },
			     	   navLinkDayClick: function(date, jsEvent) {//在日期上点击
			     		    taskEstimate(date.format());
			     	       // console.log('day', date.format()); // date is a moment
			     	       // console.log('coords', jsEvent.pageX, jsEvent.pageY);
			     	    },
			     	    navLinkWeekClick: function(weekStart, jsEvent) {//在周上面点击
                            var userName = $("#userName").val();
                            //console.log("userName = " + userName);
			     	    	createWeeklyLog(weekStart.format(), userName); //在页面 dailyLogList.jsp
			     	        //console.log('week start', weekStart.format()); // weekStart is a moment
			     	        //console.log('coords', jsEvent.pageX, jsEvent.pageY);
			     	    },
                         eventDrop : function(event, delta, revertFunc, jsEvent, ui, view){  //日程拖拽停止并且已经拖拽到其它位置了
                             // console.log(event.start.format());
                             // console.log(event.id);
                             // console.log(delta);
                             // console.log(jsEvent);
                             // console.log(ui);
                             // console.log(view);
                             // console.log("eventDrop():"+event.title);

                             moveTaskEstimate(event.id, event.start.format());
                         },


			     	    /*
			     	    ,
			            dayClick: function(date, jsEvent, view) {//空白的日期区，单击时触发  
			            	taskEstimate(date.format());
			            }
                         */
			     	 
			     	    });
			  });
        
			   	 
			   	 function callback(events){
			   		 console.log(events);
			   	 }

				
		</script>
